package com.gt.quality.system.controller;


import com.gt.quality.base.BaseCommonController;
import com.gt.quality.base.BaseCommonService;
import com.gt.quality.system.entity.SysUserRole;
import com.gt.quality.system.entity.vo.UserBindRole;
import com.gt.quality.base.pojo.LayerListViewObject;
import com.gt.quality.base.pojo.Resp;
import com.gt.quality.system.service.SysUserRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户和角色关联表(SysUserRole)表控制层
 *
 * @author makejava
 * @since 2026-11-25 16:30:08
 */
@RestController
@RequestMapping("sysUserRole")
@Tag(name = "用户关联角色")
public class SysUserRoleController extends BaseCommonController<SysUserRole> {
    /**
     * 服务对象
     */
    private SysUserRoleService sysUserRoleService;

    @Autowired
    public void setSysUserRoleService(SysUserRoleService sysUserRoleService) {
        this.sysUserRoleService = sysUserRoleService;
    }

    @Override
    public BaseCommonService<SysUserRole> getThisService() {
        return sysUserRoleService;
    }


    /**
     * 根据当前人查询角色
     */
    @PostMapping("/queryForUserId")
    @Operation(summary = "根据当前人查询角色")
    @Parameters(value = {
            @Parameter(name = "userId", description = "用户Id", in = ParameterIn.QUERY),
    })
    public Resp<LayerListViewObject> queryForUserId(@RequestParam("userId") String userId) {
        return sysUserRoleService.queryForUserId(userId);
    }

    /**
     * 当前人绑定角色
     */
    @PostMapping("/roleBindUser")
    @Operation(summary = "查询角色")
    public Resp<Boolean> roleBindUser(@RequestBody UserBindRole userBindRole) {
        return sysUserRoleService.roleBindUser(userBindRole);
    }


    /**
     * 当前人绑定角色移出
     */
    @PostMapping("/roleRemoveUser")
    @Operation(summary = "移出角色")
    public Resp<Boolean> roleRemoveUser(@RequestBody UserBindRole userBindRole) {
        return sysUserRoleService.roleRemoveUser(userBindRole);
    }


    /**
     * 根据当前角色查询授权的人
     */
    @PostMapping("/queryForRoleId")
    @Operation(summary = "根据当前角色查询授权的人")
    @Parameters(value = {
            @Parameter(name = "roleId", description = "角色Id", in = ParameterIn.QUERY),
    })
    public Resp<Object> queryForRoleId(@RequestParam("roleId") String roleId) {
        return sysUserRoleService.queryForRoleId(roleId);
    }

    @Override
    protected boolean isSuperExcel() {
        return false;
    }
}
